package com.ydsungan.worldbook.service.impl;

import com.ydsungan.worldbook.dao.BookDao;
import com.ydsungan.worldbook.pojo.Book;
import com.ydsungan.worldbook.service.BookService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class BookServiceImpl implements BookService {

    @Autowired
    private BookDao bookDao;

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public boolean addBook(Book book) {
        int effectedNum = bookDao.addBook(book);
        if (effectedNum > 0){
            return true;
        }else{
            logger.info("添加图书失败");
            throw new RuntimeException("添加图书失败");
        }
    }

    @Override
    public boolean updateBook(Book book) {
        int effectedNum = bookDao.updateBook(book);
        if (effectedNum > 0){
            return true;
        }else{
            logger.info("更新图书失败");
            throw new RuntimeException("更新图书失败");
        }
    }

    @Override
    public List<Book> getBookByMap(Map<String, Object> map) {
        return bookDao.getBookByMap(map);
    }

    @Override
    public List<Book> getBookOrderByDownloadNum(int limit) {
        return bookDao.getBookOrderByDownloadNum(limit);
    }
}
